// core/Crc32.h

#ifndef _CORE_Crc32_H_
#define _CORE_Crc32_H_

#ifndef _CORE_String_H_
#include <core/String.h>
#endif

#ifndef _CORE_Types_H_
#include <core/Types.h>
#endif

namespace CORE
{

#define CRC32_TABLE_SIZE		(256)
#define CRC32_HASH_INVALID		(0)

extern bool		s_bCrc32Initialized;
extern uint32_t	s_uiCrcTable[CRC32_TABLE_SIZE];

void			Crc32_Init();
uint32_t		Crc32_Calculate(const byte *pData, int iSize);
uint32_t		Crc32_Calculate(const CORE::String & aString);

// inline function
inline uint32_t Crc32_Calculate(const byte *pData, int iLength)
{
	if (!s_bCrc32Initialized)
		Crc32_Init();

	uint32_t uResult = 0xffffffff;

	while (iLength--)
	{
		uResult = (uResult >> 8) ^ s_uiCrcTable[(uResult & 0xFF) ^ *pData++];
	}

	return ~uResult;
}

};// namespace CORE


#endif